package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.DishFlavor;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: qingtao
 * @Date 2022/3/11 9:38
 */
public interface DishFlavorMapper {

    /**
     * 添加
     * @param dishFlavors
     * @return
     */
    Integer save(List<DishFlavor> dishFlavors);

    /**
     * 根据ID查询
     * @param dishId
     * @return
     */
    @Select("select * from dish_flavor where dish_id=#{dishId} and is_deleted=0")
    List<DishFlavor> findById(Long dishId);

    /**
     * 修改前先把所有口味改成is_deleted=1
     */
    @Update("update dish_flavor set is_deleted = 1 where dish_id=#{dishId}")
    Integer updateIsDeleted(Long dishId);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from dish_flavor where id=#{id}")
    DishFlavor findById1(Long id);

    /**
     * 添加一条数据
     * @param dishFlavor
     * @return
     */
    @Insert("insert into dish_flavor(id,dish_id,`name`,`value`,create_time,update_time,create_user,update_user,is_deleted) " +
            " values (null,#{dishId},#{name},#{value},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    Integer add(DishFlavor dishFlavor);

    /**
     * 修改 根据ID
     * @param dishFlavor
     * @return
     */
    Integer update(DishFlavor dishFlavor);

    @Delete("delete from dish_flavor where dish_id=#{dishId}")
    Integer deleteByDishId(Long dishId);
}
